home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / READINTO.C < prev    next >
Text File  |  1992-05-14  |  2KB  |  38 lines

  1. /************************************************************************************/
  2. /*    ReadIntoTE                                                                        */
  3. /*                                                                                    */
  4. /*    Reads open file into existing TextEdit record                                    */
  5. /************************************************************************************/
  6.  
  7. #include "MyHeaders.h"
  8.  
  9. long ReadIntoTE(int pathRefNum, TEHandle hTE)
  10. {
  11.     long    byteCount = 256;                    /* bytes requested / returned        */
  12.     OSErr    readErr;                            /* return from I/O routines            */
  13.     long    bytesRead = 0;                        /* total of bytes returned            */
  14.     Ptr        beginP;                                /* ptr to begin of temp I/O area    */
  15.     Ptr        nextP;                                /* ptr to next avail pos in I/O ara    */
  16.  
  17.     CursorSelect (NIL, NIL, watchCursor);        /* set watch cursor                    */
  18.     
  19.     readErr = SetFPos (pathRefNum, fsFromStart, 0);    /* position file ptr to begin    */
  20.     
  21.     beginP = NewPtr(32767);                        /* get a temporary I/O area            */
  22.     nextP = beginP;                                /* next avail pos is at top            */
  23.     
  24.     readErr = noErr;                            /* initialize before read loop        */
  25.     while (readErr == noErr)                    /* read till error or EOF            */
  26.         {
  27.         readErr = FSRead (pathRefNum, &byteCount, nextP);    /* read a block            */
  28.         bytesRead += byteCount;                                /* add bytes to total    */
  29.         nextP += byteCount;                                    /* reset nxt avail pos    */
  30.         }
  31.  
  32.     TESetText (beginP, bytesRead, hTE);            /* copy into TE record                */
  33.     TESetSelect (0, 0, hTE);                    /* set selection at top                */
  34.  
  35.     DisposPtr (beginP);                            /* release temporary I/O area        */
  36.     
  37.     return bytesRead;                            /* return total no of bytes            */
  38. }